<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../css/mui.min.css"/>
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../css/general.css"/>
		<link rel="stylesheet" type="text/css" href="../css/mui.picker.min.css"/>
		<link rel="stylesheet" type="text/css" href="../css/mui.poppicker.css"/>
		<link rel="stylesheet" type="text/css" href="../workbench/analysis/empcss.css"/>
		<style type="text/css">
			.content{
				width: 100%;
				background-color: #F2F2F2;
				padding: 10px;
			}
			.search{
				display: flex;
				justify-content: center;
				align-content: center;
				padding: 10px;
				background-color: white;
			}
			.stext{
				width: 25%;
				text-align: center;
				display: flex;
				justify-content: center;
				align-items: center;
				border-right:1px solid #C7C7CC;
			}
			.simg{
				width: 30px;
				height: 30px;
			}
			.simg>img{
				width: 100%;
				height: 100%;
			}
			.ssdiv{
				width: 75%;
			}
			.ssinp{
				width: 100%;
				height: 100%;
				border: 0;
				padding-left: 10px;
			}
			::-webkit-input-placeholder{
				font-size: 0.8em;
				color: #999999;
			} 
			.sjx{
				margin: auto;
				width: 0;
				height: 0;
			    border:10px solid transparent;
				border-top: 10px solid #000000;
				position: relative;
				top: 20%;
			}
			.doclist{
				width: 100%;
				margin-bottom: 0.2em;
				padding: 0.5em;
				background-color: white;
				position: relative;
			}
			.doclist>div{
				padding: 0.2em;
			}
			.doclist>div:first-child{
				display: flex;
				align-items: center;
				justify-content: space-between;
			}
			
			.danhang{
				width: 60%;
				text-overflow: -o-ellipsis-lastline;  
				overflow: hidden;  
				text-overflow: ellipsis;  
				display: -webkit-box;  
				-webkit-line-clamp: 1;  
				-webkit-box-orient: vertical;
			}
			
			.tuidandiv{
				position: absolute;
				width: 20%;
				right: 0;
				top: -10px;
				overflow: hidden;
				transform:rotate(-20deg);
			}
			.tuidandiv>img{
				width: 100%;
			}
		</style>
	</head>



	<body>
		<header class="mui-bar mui-bar-nav hbg">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left colorw"></a>
		    <h1 class="mui-title">库存单据</h1>
		</header>
		<div class="mui-content">
		    <!--
            	作者：592176224@qq.com
            	时间：2019-02-25
            	描述：
            
		    <div class="content">
		    	<div class="search">
		    		<div class="simg">
		    			<img src="../images/60x60.gif"/>
		    		</div>
		    		<div class="ssdiv">
		    			<input class="ssinp" type="" name="" id="" value=""  placeholder="请输入编码或名称"/>
		    		</div>
		    		<div class="simg">
		    			<img src="../images/60x60.gif"/>
		    		</div>
		    	</div>
		    </div>
		    -->
		    <div id="">
		    	<div class="mui-input-row borbot" >
					<label>门店:</label>
		    		<div class="place items">
					    <button id='level' type="button" class="mui-btn mui-btn-blue mui-btn-outlined">门店选择</button>
					</div>
				</div> 
		    </div>
		    <div class="content">
		    	<div class="search">
		    		<div class="stext fe09" id="stext">
		    			入库
		    			<div class="sjx">
		    			</div>
		    		</div>
		    		<div class="ssdiv">
		    			<input id="keyvalue" class="ssinp" type="" name="" id="" value=""  placeholder="请输入单号"/>
		    		</div>
		    		<div class="simg" onclick="">
		    			<img src="../img/ss-img2.png"/>
		    		</div>
		    	</div>
		    </div>
		    <div class="context" id="doclistid">
		    	
		    	
		    	
		    	
		    </div>
		     <div class="morediv hidden" id="moreid">
		   		<span onclick="more_list()">更多</span>
		   	</div>
		</div>
		
		
		<script src="../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/mui.min.js"></script>
		<script src="../js/mui.picker.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/mui.poppicker.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/req.js"></script>
		<script src="../js/muishow.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var type = 1,
			store_id = '';	//门店id
			
			var slist = [],
			page = 1;	
			
			window.onload = function(){
				
				mui.init();
				mui.ready(function() {
                var stextPicker = new mui.PopPicker();
                stextPicker.setData([{
                    value: '1',
                    text: '入库'
                }, {
                    value: '2',
                    text: '出库'
                }, {
                    value: '3',
                    text: '盘点'
                }, {
                    value: '4',
                    text: '调拨'
                }]);
                var stext = document.getElementById('stext');
                stext.addEventListener('tap', function(event) {
                    stextPicker.show(function(items) {
                        stext.innerHTML = items[0].text + '<div class="sjx"></div>';
                        type = items[0].value;
                        slist = [];
                        getdoclist();
                    });
                }, false);
              	store();
            });
            
				getdoclist();
			}
			
			//获取门店列表
			function store(){
				var data = {
					url:"/api/store/lst",
					data:{
						access_token:acctoken(),
						
					}
				}
				ajax(data,function(res){
					console.log("门店列表",res)
					setpop(res.data)
				})
			}
			function setpop(list){
				var list1 = [];
				for(var i = 0; i < list.length; i++){
							var str = {value:list[i].id,text:list[i].store_name}
							list1.push(str);
				}
				var levelPicker = new mui.PopPicker();
                levelPicker.setData(list1);
                var level = document.getElementById('level');
                level.addEventListener('tap', function(event) {
                    levelPicker.show(function(items) {
                        level.innerText = items[0].text;
                        store_id = items[0].value;
                        //返回 false 可以阻止选择框的关闭
                        //return false;
                        slist = [];
                        getdoclist();
                    });
                }, false);
			}
			
			//获取单据列表
			function getdoclist(){
				var data = {
					url:"/api/product/stream",
					data:{
						access_token:acctoken(),
						store_id:store_id,
						do_type:type,
						page:page,
					}
				}
				ajax(data,function(res){
						console.log("单据列表",res);
							var list = res.data.data;
								if(list.length){
									list.forEach(function(item,index){
										slist.push(item);
									})
									slist = remove_duplicate(slist);
									setdoclist(slist);
									$("#moreid").removeClass("hidden");
									if(list.length < res.data.per_page){
										$("#moreid").addClass("hidden");
									}
								}else{
									if(page == 1){
										var str = '<div class="nolistdiv">暂无记录<div>';
										g("doclistid").innerHTML = str;
										$("#moreid").addClass("hidden");
									}else{
										page--;
										$("#moreid").addClass("hidden");
										mui.toast('没有更多数据了');
									}
								}
				})
				
			}
			
			function setdoclist(list){
				var tmian = g("doclistid");
				var str = '';
				if(list&&list.length > 0){
					for(var i = 0; i < list.length; i++){
						str += '<div class="doclist" onclick="gpdetail('+list[i].id+')">'+
							'<div class="">'+
			    			'<div class="danhang">'+
			    			list[i].do_type+':'+list[i].order_name +
			    			'</div><div class="">';
			    			//if(list[i].do_type == 1){
			    			//	str += '+'+list[i].all_count;
			    			//}else{
			    				str += list[i].all_count;
			    			//}
			    			str += 	'</div></div><div class="fe09">'+
			    			list[i].createtime+
			    			'</div>';
			    			if(list[i].is_refund){
			    				str += '<div class="tuidandiv">'+
									    '<img src="../img/tuidan.png"/>'+
									    '</div>';
			    			}
			    			str += '</div>';
					}
				}else{
					str += '<div class="nolistdiv">暂无数据</div>'
				}
		    	 
		    	tmian.innerHTML = str;
			}
			
			function gpdetail(rid){
				
				 mui.openWindow({
                        url: 'inventory-documents-detail.html?rid='+rid,
                        id: 'inventory-documents-detail',
                        extras: rid
                        
                });
				
			}
			//刷新
			function onshow(){
				getdoclist();
			}
			
			//更多
			function more_list(){
				page++;
				getdoclist();
			}
		</script>
	</body>

</html>